// import { ModuleTest } from './notadd-module';
//---------------------------------------------------------------------
import { STATUS_TEXT } from '@notadd/http'
import { Controller, Injector } from '@notadd/core'

import {
    HttpMethod,
    Header,
    MIME,
    Db,
    HttpStatus,
} from '@notadd/http'

import {
    Get,
    Html,
    Js,
    Put,
    Post,
    Delete
} from '@notadd/http'

import {
    REQ,
    HTTP_REQ,
    RES,
    HTTP_RES,
    HTTP_SERVER,
    REQ_ID,
    REQ_START_TIME,
    HTTP_HANDLER,
    HTTP_BODY,
    HTTP_URL,
    HTTP_IP,
    HTTP_PORT
} from '@notadd/http';

import { SkipSelfOptions } from '@notadd/core'
//---------------------------------------------------------------------
import { InjectionToken } from '@notadd/core';
const TEST_ABC = new InjectionToken<string>('@notadd/test TEST_ABC');
//---------------------------------------------------------------------
@Controller()
export class HttpController {
    constructor(private injector: Injector) { };
    @Get("/")
    async helloworld(): Promise<string> {
        console.log(`injector.scope = ${this.injector.scope}`);
        const req = this.injector.get(REQ);
        const res = this.injector.get(RES);
        const httpReq = this.injector.get(HTTP_REQ);
        const httpRes = this.injector.get(HTTP_RES);
        const httpServer = this.injector.get(HTTP_SERVER);
        const reqId = this.injector.get(REQ_ID);
        const reqStartTime = this.injector.get(REQ_START_TIME);
        // const httpHeaders = this.injector.get(HTTP_HANDLER);
        const httpBody = this.injector.get(HTTP_BODY);
        // const httpUrl = this.injector.get(HTTP_URL);
        // const httpIP = this.injector.get(HTTP_IP);
        // const httpPort = this.injector.get(HTTP_PORT);
        const testAbc = this.injector.get(TEST_ABC);

        console.log('GET /');
        httpRes.statusCode = HttpStatus.PartialContent;
        httpRes.statusMessage = STATUS_TEXT.get(HttpStatus.PartialContent) as string;
        return testAbc;
    }
}
//---------------------------------------------------------------------
import { Module } from '@notadd/core';

@Module({
    imports: [],
    providers: [
        {
            provide: TEST_ABC,
            useValue: "caonima",
        }
    ],
    controllers: [
        HttpController,
    ],
})
export class HttpApiModule { }
//---------------------------------------------------------------------
// import { Module } from '@notadd/core';
import { HttpModule } from '@notadd/http'
// import { GraphqlModule } from '@notadd/graphql'
@Module({
    imports: [
        HttpModule.forRoot(3005),
        // GraphqlModule.forRoot('/graphql'),
        HttpApiModule
    ]
})
export class ApiModule { }
//---------------------------------------------------------------------
import { platformNode } from '@notadd/platform-node';
import { MAIN_PATH } from '@notadd/core';
import { Router } from '@notadd/core';
platformNode([
    {
        provide: MAIN_PATH,
        useValue: __filename,
    }
])
    .bootstrapModule(ApiModule)
    .then(async (res) => {

        const router = res.injector.get(Router);
        console.log("启动成功");
    }).catch(async (err) => {
        console.log(err);
    });
//---------------------------------------------------------------------